﻿using System;
using System.Collections;
using System.Collections.Generic;

using AUV5.Model;
using AUV5.DAL.Interface;

namespace AUV5.DAL.Dao
{
    /// <summary>
    /// 功能：     OrderItem业务接口的实现
    /// 作者：     lwl
    /// 日期：     2011/10/14
    /// 修改日期： 
    /// 修改人：
    /// 修改内容：
    /// </summary>
    public class OrderItemSqlMapDao : BaseSqlMapDao, IOrderItemDao
    {
        private static OrderItemSqlMapDao instance = null;
        private static object syncRoot = new object();

        private OrderItemSqlMapDao()
        {
            //
            // TODO: 此处添加OrderItemSqlMapDao的构造函数
            //
        }
        public static IOrderItemDao Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                        {
                            instance = new OrderItemSqlMapDao();
                        }
                    }
                }
                return instance;
            }
        }

        /// <summary>
        /// 得到最大行数
        /// </summary>
        /// <returns></returns>
        public int GetMaxCounts()
        {
            try
            {
                return (int)ExecuteQueryForObject("SelectOrderItemByMaxCounts", null);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 得到列表
        /// </summary>
        /// <returns></returns>
        public System.Collections.Generic.IList<OrderItem> GetList()
        {
            try
            {
                return ExecuteQueryForList<OrderItem>("SelectOrderItem", null);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 通过不同参数得到列表
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public System.Collections.Generic.IList<OrderItem> GetListByParameters(object objParameters)
        {
            try
            {
                return ExecuteQueryForList<OrderItem>("SelectOrderItemByParameters", objParameters);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 得到明细
        /// </summary>
        /// <param name="OrderItemID"></param>
        /// <returns></returns>
        public OrderItem GetDetail(System.String orderitemid)
        {
            try
            {
                return ExecuteQueryForObject<OrderItem>("SelectOrderItem", orderitemid) as OrderItem;
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 新建
        /// </summary>
        /// <param name="orderitem"></param>
        /// <returns></returns>
        public object Add(OrderItem orderitem)
        {
            //int id = GetId("OrderItem");
            //orderitem.OrderItemID = id;

            try
            {
                return ExecuteInsert("InsertOrderItem", orderitem);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="orderitem"></param>
        /// <returns></returns>
        public int Update(OrderItem orderitem)
        {
            try
            {
                return ExecuteUpdate("UpdateOrderItem", orderitem);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="OrderItemID"></param>
        /// <returns></returns>
        public int Delete(System.String orderitemid)
        {
            try
            {
                return ExecuteDelete("DeleteOrderItem", orderitemid);
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="orderitem"></param>
        /// <returns></returns>
        public int Delete(OrderItem orderitem)
        {
            try
            {
                return ExecuteDelete("DeleteOrderItem", orderitem.OrderItemID);
            }
            catch
            {
                throw;
            }
        }

        #region##通过条件得到订单项个数
        /// <summary>
        /// 通过条件得到订单项个数
        /// 创建人：Wilson
        /// 创建时间：2011-10-12
        /// </summary>
        /// <param name="objParamters"></param>
        /// <returns></returns>
        public int GetOrderItemQuantityCountByCondition(object objParamters)
        {
            try
            {
                return (int)ExecuteQueryForObject("SelectOrderItemByConditon", objParamters);
            }
            catch 
            {
                
                throw;
            } 
        }
        #endregion


        #region## 通过订单ID得到订单项详情
        /// <summary>
        /// 通过订单ID得到订单项详情
        /// 创建人：Wilson
        /// 创建时间：2011-10-30
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public OrderItem GetOrderItemByOrderID(string orderId)
        {
            try
            {
                return ExecuteQueryForObject<OrderItem>("SelectOrderItemByOrderID", orderId) as OrderItem;
            }
            catch
            {
                throw;
            }
        }
        #endregion


        #region## 通过订单ID得到订单附加服务
        /// <summary>
        /// 通过订单ID得到订单附加服务
        /// 创建人：Wilson
        /// 创建时间：2011-12-18
        /// </summary>
        /// <param name="objParamters"></param>
        /// <returns></returns>
        public IList<OrderItem> GetOrderItemExtra(object objParamters)
        {
            try
            {
                return ExecuteQueryForList<OrderItem>("SelectOrderItemExtra", objParamters);
            }
            catch
            {
                throw;
            }
        }
        #endregion
    }
}
